#!/bin/sh

set -e

show_status() {
  echo "Container status:"
  docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" | grep -E "NAMES|hyperf_"
}

show_logs() {
  target="$1"
  case "$target" in
    gateway)
      docker logs -f hyperf_gateway ;;
    notice)
      docker logs -f hyperf_notice_local ;;
    data)
      docker logs -f hyperf_data_local ;;
    all)
      echo "---- gateway ----"; docker logs --since=10m hyperf_gateway || true
      echo "---- notice ----"; docker logs --since=10m hyperf_notice_local || true
      echo "---- data ----"; docker logs --since=10m hyperf_data_local || true ;;
    *)
      echo "Usage: $0 logs [gateway|notice|data|all]" && exit 1 ;;
  esac
}

cmd="$1" ; shift || true

case "$cmd" in
  status)
    show_status ;;
  logs)
    show_logs "$1" ;;
  *)
    echo "Usage: $0 [status|logs {gateway|notice|data|all}]" && exit 1 ;;
esac

